Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cldrjs

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cldrjs

Simple CLDR traverser

  • 0.4.8
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is cldrjs?

The cldrjs npm package is a JavaScript library that provides access to the Unicode Common Locale Data Repository (CLDR). It allows developers to handle internationalization (i18n) tasks such as formatting dates, times, numbers, and currencies, as well as handling plurals and other locale-specific data.

What are cldrjs's main functionalities?

Locale Data Access

This feature allows you to access locale-specific data. In this example, we create a new CLDR instance for the English locale and retrieve the display names for languages.

const Cldr = require('cldrjs');
const en = new Cldr('en');
console.log(en.get('localeDisplayNames/languages'));

Number Formatting

This feature allows you to format numbers according to locale-specific rules. In this example, we use the Globalize library along with cldrjs to format a number in the English locale.

const Cldr = require('cldrjs');
const Globalize = require('globalize');
Globalize.load(require('cldr-data/main/en/numbers.json'));
Globalize.load(require('cldr-data/supplemental/likelySubtags.json'));
Globalize.locale('en');
console.log(Globalize.numberFormatter()(1234567.89));

Date and Time Formatting

This feature allows you to format dates and times according to locale-specific rules. In this example, we use the Globalize library along with cldrjs to format the current date and time in the English locale.

const Cldr = require('cldrjs');
const Globalize = require('globalize');
Globalize.load(require('cldr-data/main/en/ca-gregorian.json'));
Globalize.load(require('cldr-data/supplemental/likelySubtags.json'));
Globalize.locale('en');
console.log(Globalize.dateFormatter({ datetime: 'medium' })(new Date()));

Pluralization

This feature allows you to handle pluralization according to locale-specific rules. In this example, we use the Globalize library along with cldrjs to determine the plural category for numbers in the English locale.

const Cldr = require('cldrjs');
const Globalize = require('globalize');
Globalize.load(require('cldr-data/main/en/plurals.json'));
Globalize.load(require('cldr-data/supplemental/plurals.json'));
Globalize.locale('en');
console.log(Globalize.plural(1)); // 'one'
console.log(Globalize.plural(2)); // 'other'

Other packages similar to cldrjs

Keywords

FAQs

Package last updated on 26 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc